const carmodul_collection = db.collection("carmodul");
var md5 = require("md5");

(function() {
    // 构造函数
    var _con = function(info) {
        // console.log(info);
        var self = this;
        // 类别
        if (info) {
            self.type = "user";
            // 自有id,u_+2位随机数+当前时间的毫秒数转16进制 
            self.id = "carmod_" + Math.random().toString(16).substr(2, 4) + (new Date()).getTime().toString(16);
            // 积分
            self.integral = 0;
            // 论坛昵称
            self.nickname = info.nick_name || info.name || info.nickname || "user_" + Math.random().toString(16).substr(2, 8);
            // 论坛头像
            self.head_img = info.head_img;
            // 论坛等级
            self.level = info.level;
            // 手机号
            self.mobile_phone = info.mobile_phone;
            // 邮箱
            self.email = info.email;
            // 商城用户_id
            self.shop_id = "";
            // 话题数
            self.posttotal = info.posttotal || 0;
            // 回复数
            self.replytotal = info.replytotal || 0;
        };
    };
    module.exports = _con;
    
    //查找房车型号
    _con.prototype.getlist = co.wrap(function*(){
        var self = this;
        var param = {
            sort: {
                createtime: -1
            }
        };
        return yield mongo.find(carmodul_collection,param);
    });

    //查找房车型号详情
    _con.prototype.getdetail = co.wrap(function*(_id){
        var self = this;
        if(!_id){
            return printError('型号不存在');
        }
        var param = {
            query:{
                _id:_id
            }
        }
        var arr_carmodule = yield mongo.findOne(carmodul_collection,param);
        if(!arr_carmodule){
            return printError('型号不存在');
        }else{
            return arr_carmodule;
        }
    });

    _con.prototype.getpricelist = co.wrap(function*(){
        var price_connect = db.collection("price");
        var data = yield mongo.find(price_connect);
        return data;
    })
}());
